﻿@{
    ViewData["Title"] = "Scan";
    Layout = null;
}
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,minimum-scale=1,maximum-scale=1,viewport-fit=cover">
    <title>@ViewBag.SysName</title>
    <script src="~/lib/jquery-1.12.4.min.js" asp-append-version="true"></script>
    <script src="~/js/app.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script>
        var globalData = {
            modules: [],
            user: {},
            baseUrl: '@(Context.Request.PathBase)',
            todoList: [],
            todoIndex:0,
            loginUrl: '@(Url.Action("Login", "Sys_User"))',
        };
    </script>
</head>
<body>
    <a onclick="scan();">扫码</a>
    <script type="text/javascript">
        utils.ajaxPost(
            '@(Url.Action("GenJSSDK", "WX_MP"))',
            {
                appid:'wxac199e427ea09028',
                url:window.location.href.split("#")[0],
                callback:'',
            }
            , function (resp) {
            if(resp&&resp.r&&resp.data)
            {
                const con = resp.data||{};
                wx.config({
                    // debug: con.debug,
                    debug:true,
                    appId: con.appId,
                    timestamp: con.timestamp,
                    nonceStr: con.nonceStr,
                    signature: con.signature,
                    jsApiList: ['scanQRCode']
                });
            }
            }, function (msg) {
                console.log(msg);
            },
            true
            );
function scan(){
                console.log('scan');
    
        // 调用扫一扫接口
        wx.ready(function () {
                console.log(' wx.ready');
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果
                scanType: ["qrcode", "barcode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                    var result = res.resultStr; // 当needResult为1时，扫码返回的结果
                    console.log(result);
                },
                fail: function (err) {
                    console.error(err.errmsg);
                }
            });
        });
}
    </script>
</body>
</html>